package com.zlsy.thread.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author zhouliang
 * @date 2020/7/1 20:16
 */
public class NewCachedThreadPoolTest {

    /**
     * 特点：无界线程池，具有回收多余线程的功能。
     *
     * 弊端：最大线程数被设置成了Integer.MAX_VALUE，这可能会创建数量非常多的线程，甚至导致OOM。
     */
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newCachedThreadPool();
        for (int i = 0; i < 100; i++) {
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName());
                }
            });
        }
        executorService.shutdown();
    }
}
